package com.sfx.算法专题.位运算;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: sfx
 * Date: 2023-08-21
 * Time: 8:59
 */
public class Code_2_countBits {


    static class Solution {
        public int[] countBits(int n) {
            int[] res = new int[n+1];
            int index = 0;
            for(int i =0;i<=n;++i) {
                int ans = 0;
                int x = i;
                while(x != 0) {
                    x &= (x-1);
                    ans ++;
                }
                res[index++] = ans;
            }
            return res;
        }
    }
}
